from flask import Flask
from celery import Celery, Task


def init_app(app: Flask):
    class CeleryDaemon(Task):
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery_app = Celery(app.name, task_cls=CeleryDaemon)
    print(app.config.get("CELERY"))
    celery_app.config_from_object(app.config.get("CELERY"))
    celery_app.set_default()
    app.extensions['celery'] = celery_app
